# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Maintainer: Andreas 'Segaja' Schleifer <segaja at archlinux dot org>

_gemname='thor'
pkgname="ruby-${_gemname}"
pkgver=1.2.1
pkgrel=1
pkgdesc='Toolkit for building powerful command-line interfaces'
url='https://github.com/erikhuda/thor'
arch=('any')
license=('MIT')
depends=('ruby')
makedepends=('ruby-rdoc')
checkdepends=('ruby-bundler' 'ruby-rake' 'ruby-rspec' 'ruby-webmock')
options=('!emptydirs')
source=("${url}/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz"
        tests.patch)
sha512sums=('88e58b6ca6c812cb84ab59e0ee8afcd8fa70b6c24d403cd5ea05d1d40ac30e85f2c7412611cc176eb541d16878e309d25c7e4284f64c760475925ffe359250b9'
            'd327cbff295092c46ec693003b5b3ec1a20fcbff943dbb9519f650c38b52e17168ef71c59deae222f1ecace19e139e8eecfea1c6d58f7871d2cc7ec1426ee87c')

prepare() {
  cd "${_gemname}-${pkgver}"

  # remove unused parts from tests and replace git usages
  patch --verbose --strip=1 --input=../tests.patch

  # update gemspec to allow newer version of the deps
  sed --in-place --regexp-extended 's|~>|>=|g' "${_gemname}.gemspec"
}

build() {
  cd "${_gemname}-${pkgver}"

  gem build "${_gemname}.gemspec"
}

check() {
  cd "${_gemname}-${pkgver}"

  rspec spec
}

package() {
  cd "${_gemname}-${pkgver}"

  local _gemdir="$(gem env gemdir)"

  gem install --ignore-dependencies --no-user-install --install-dir "${pkgdir}${_gemdir}" --bindir "${pkgdir}/usr/bin" ${_gemname}-${pkgver}.gem

  install -D --mode=644 *.md --target-directory "${pkgdir}/usr/share/doc/${pkgname}"
  install -D --mode=644 LICENSE.md "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"

  rm "${pkgdir}/${_gemdir}/cache/${_gemname}-${pkgver}.gem"
}

# vim: ts=2 sw=2 et:
